<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UtilsController extends Controller
{
    public function upload(Request $request)
    {
        $request->validate([
            'file' => "required|file|max:20480",
        ], [
            'file.required' => '文件不能为空',
            'file.file' => '文件类型不正确',
            'file.max' => '文件大小不能超过 20 MB',
        ]);

        $file = $request->file('file');
        $file->storeAs(
            'public/' . Date('Ym'),
            $file->hashName(),
        );
        return responder()->success([
            'url' => asset('storage/' . Date('Ym') . '/' . $file->hashName(), env('APP_HTTPS', false)),
            'name' => $file->getClientOriginalName(),
        ]);
    }
}
